
import path from "path"
import aliases from "./alias"
import babel from  "@rollup/plugin-babel"
// import rollupResolve from "rollup-plugin-node-resolve"
const flow = require('rollup-plugin-flow-no-whitespace')
const alias = require('rollup-plugin-alias')

const banner =
  '/*!\n' +
  ` * Vue.js 2.6.11\n` +
  ` * (c) 2025-${new Date().getFullYear()} Fly\n` +
  ' * Released under the MIT License.\n' +
  ' */'

const resolve = p => {
    const base = p.split('/')[0]
    if (aliases[base]) {
        return path.resolve(aliases[base], p.slice(base.length + 1))
    } else {
        return path.resolve(__dirname, '../', p)
    }
}

const builds = {
    'web-runtime-cjs-dev': {
        // entry: resolve('web/entry-runtime.js'),
        entry: resolve("test/1.js"),
        dest: resolve('dist/vue.runtime.common.dev.js'),
        format: 'cjs',
        env: 'development',
        banner
    },
}

function genConfig (name) {
    const opts = builds[name];
    const config = {
        input: opts.entry,
        output: {
            file: opts.dest,
            format: opts.format,
            banner: opts.banner,
            name: opts.moduleName || "Vue"
        },
        plugins: [
            flow(),
            // 别名，外部依赖加载（配置文件 ./alias.js）
            alias(Object.assign({}, aliases, opts.alias)),
            // 需要 babel 转换, 如 export let shouldObserve: boolean = true;
            babel({
                babelHelpers: "bundled",
                exclude: "node_modules/**"
            })
        ].concat(opts.plugins || [])
    }
    return config;
}

const targetName = process.env.TARGET || "web-runtime-cjs-dev";
export default genConfig(targetName);